import Cookies from 'js-cookie'
import { defineStore } from 'pinia'
import { ref, reactive } from 'vue'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
export const useAppStore = defineStore('app', () => {
    const sidebar = reactive({
        opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
        withoutAnimation: false
    })
    const device = ref('desktop')
    const size = ref(Cookies.get('size') || 'medium')
    //语言切换
    const locale = ref(zhCn)

    function toggleSideBar() {
        sidebar.opened = !sidebar.opened
        sidebar.withoutAnimation = false
        if (sidebar.opened) {
            Cookies.set('sidebarStatus', 1)
        } else {
            Cookies.set('sidebarStatus', 0)
        }
    }
    function closeSideBar(newWithoutAnimation) {
        Cookies.set('sidebarStatus', 0)
        sidebar.opened = false
        sidebar.withoutAnimation = newWithoutAnimation
    }
    function toggleDevice(newDevice) {
        device.value = newDevice
    }
    function setSize(newSize) {
        size.value = newSize
        Cookies.set('size', newSize)
    }
    function setLocale(_locale) {
        locale.value = _locale
    }
    return {
        sidebar,
        device,
        size,
        locale,
        toggleSideBar,
        closeSideBar,
        toggleDevice,
        setSize,
        setLocale
    }
})
